package edu.bu.cs673.superkids123.common.model;

import java.io.IOException;
import java.security.GeneralSecurityException;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import edu.bu.cs673.superkids123.SecurityUtil;

@Entity
@Table(name = "Parents")
@PrimaryKeyJoinColumn(name = "UserID")
public class Parent extends User {

	@Column(name = "Password")
	private String password;

	@Column(name = "UserName")
	private String userName;

	@Column(name = "Email")
	private String email;

	// Hibernate need a non argument constructor
	public Parent() {

	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getClearPassword() {
		try {
			return SecurityUtil.decryptProperty(password);
		} catch (GeneralSecurityException e) {
			// TODO This is not the correct approach to passwords
			return password;
		} catch (IOException e) {
			// TODO This is not the correct approach to passwords
			return password;
		}
	}

}
